<?php

if($_POST['act'] == 'act'){
	$param = $_POST;

	foreach($param['row'] as $key => $val){
		$param['statu'][$key] = $_POST['statu'][$key] ? $_POST['statu'][$key] : 0 ;
		$time = time();
		if(empty($param['ids'][$key])){
			$sql = "insert into ".SPOTSEAT." (`spot_id`,`model_id`,`row`,`seat`,`statu`,`add_at`) values (
			'{$param['spot_id']}','{$param['model_id']}','$val','{$param['seat'][$key]}','{$param['statu'][$key]}','$time')";
			$db->query($sql);

		} else {

			$sql = "update ".SPOTSEAT." set row = '$val',statu='{$param['statu'][$key]}', seat = '{$param['seat'][$key]}' where id = '{$param['ids'][$key]}' ";
			$db->query($sql);

		}

		if(!empty($param['delete_id'][$key])){
			$sql = "delete from ".SPOTSEAT." where id = '{$param['delete_id'][$key]}' ";
				$db->query($sql);
		}

	}

	echo "<script>window.parent.main.document.location.reload();window.parent.DialogManager.close('spot_seat');</script>";

}else {
	$model_id = $_GET['model_id'] ? $_GET['model_id'] : 0;
	$spot_id = $_GET['spot_id'] ? $_GET['spot_id'] : 0;
	$sql="select * from ".SPOTSEAT." where model_id ='$model_id' ";
	$db->query($sql);
	$spot_seat = $db->getRows();

}
$tpl->assign("spot_id",$spot_id);
$tpl->assign("model_id",$model_id);
$tpl->assign("list",$spot_seat);
$tpl->assign("spot_id",$spot_id);
$tpl->assign("config",$config);
$tpl->assign("lang",$lang);
$tpl->display("spot_seat.htm");

?>